import request from '@/utils/request'
import * as MD5 from 'md5.js'
import * as qs from 'qs'

export function login(account, password, rememberMe) {
  return request({
    url: '/api/pub/manager/login',
    method: 'post',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    data: qs.stringify({ account, password: new MD5().update(password).digest('hex'), rememberMe })
  }).then(json => {
    if (json.result) {
      // data.data.token = data.token
      return json.data
    } else {
      throw new Error(json.message)
    }
  })
}

export function getInfo() {
  return request.get('/api/sys/staff/account')
}

export function logout() {
  return request.post('/api/pub/logout')
}
